﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using System.IO;
using MySql.Data.MySqlClient;
using System.Data.OleDb;
using H = functionService.shorts;
using da = functionService.DATECOD;
using fr = HK.FiscalRegistrar.FiscalRegistrar;
using vv = functionService.serfun_city7;
using rz = functionService.serfun_city7.rz;
using nameCod = functionService.nameCod;

namespace city7
{
    
    public partial class FormRezList : Form
    {
        functionService.prm_city q;
        rzpt.modeWAED currentMode;
        DataTable dts;



        int linesPrint, currentPage;

        public FormRezList()
        {
            InitializeComponent(); InitializeComponentMy();
            // dataGridView1.CurrentCell = dataGridView1[0, 7];

        }

        private void InitializeComponentMy()
        {
            q = new functionService.prm_city();

            string s = q.tk((int)ETALON.param.server_1);
            q.con.co(s);
            refresh();
            set();
            setMode(city7.rzpt.modeWAED.work);

            vv.rz.add_prod_default = "- (888)";
            vv.rz.add_sirT_default = "- (888)";
            vv.rz.currentColumn = 0;
            vv.rz.currentRow = 0;
        }

        void setMode(rzpt.modeWAED mo)
        {
            currentMode = mo;
            if (mo == city7.rzpt.modeWAED.work)
            {
                setColor(Color.LightGray, Color.White);
                dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                refresh();
            }
            else if (mo == city7.rzpt.modeWAED.add)
            {
                setColor(Color.SteelBlue, Color.LightSkyBlue);
                dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;

               
            }
            else if (mo == city7.rzpt.modeWAED.edit)
            {
                setColor(Color.Green, Color.LightGreen);
                dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;
            }
            else if (mo == city7.rzpt.modeWAED.delete)
            {
                setColor(Color.Coral, Color.Coral);
                dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            }
            else if (mo == city7.rzpt.modeWAED.non)
            {
                setColor(Color.LightGray, Color.White);
                dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            }

        }
        void setColor(Color c1, Color c2)
        {
            dataGridView1.Columns[0].DefaultCellStyle.BackColor = c1;
            dataGridView1.Columns[1].DefaultCellStyle.BackColor = c2;
            dataGridView1.Columns[2].DefaultCellStyle.BackColor = c1;
            dataGridView1.Columns[3].DefaultCellStyle.BackColor = c2;
        }
        void set()
        {


            dataGridView1.Columns[0].DefaultCellStyle.BackColor = Color.LightGray;
            dataGridView1.Columns[2].DefaultCellStyle.BackColor = Color.LightGray;
            dataGridView1.Columns[3].DefaultCellStyle.BackColor = Color.LightGray;

            dataGridView1.Columns[0].Width = 350;
            dataGridView1.Columns[1].Width = 350;
            dataGridView1.Columns[2].Width = 50;
            dataGridView1.Columns[3].Width = 50;

            dataGridView1.Columns[0].HeaderText = "Наименование Продукции";
            dataGridView1.Columns[1].HeaderText = "Наименование РЕЦЕПТУРНОЕ";
            dataGridView1.Columns[2].HeaderText = "КодП";
            dataGridView1.Columns[3].HeaderText = "КодПр";

        }
        void cellclick()
        {
            if (currentMode == city7.rzpt.modeWAED.add)
            {
                cellclick_add();
            }
            else if (currentMode == city7.rzpt.modeWAED.edit)
            {
                cellclick_edit();
            }
            else if (currentMode == city7.rzpt.modeWAED.delete)
            {
                cellclick_del();
            }
            else if (currentMode == city7.rzpt.modeWAED.work)
            {
                cellclick_work();
            }
            else if (currentMode == city7.rzpt.modeWAED.non)
            {
                cellclick_non();
            }
        }
        private void cellclick_add()
        {
            int i = nameCod.readCod_int(SELECTprod);
            q.UpdateData(rz.sql.rz_insert_To_list_sc_mainlistr(i,888)); refresh(i);
        }
        private string SELECTprod
        {
            get
            {
                string s = "- (888)";

                if (vv.rz.add_prod_default == "- (888)")
                {
                    DataTable dt = q.selectAny(
                       string.Concat("call `city`.`select_listSc_to_mainListR` ();"));

                    ETALON.listAnyEdit f =
                        new ETALON.listAnyEdit("city", "list_sc", "cod<888"); f.ShowDialog();
                    if (f.IsOK)
                    {
                        s = f.sText; vv.rz.add_prod_default = s; toolStripStatusLabel1.Text = s;
                    }
                }
                else
                {
                    s = vv.rz.add_prod_default;
                }
                return s;
            }
        }
        void refresh(int xxx, int yyy)
        {

            dts = q.selectAny("call `city`.`select_list_sc_mainlistr`();");
                dataGridView1.DataSource = dts;
                dataGridView1.CurrentCell = dataGridView1[xxx, yyy];
           
        }
        //DataTable dt = q.selectAny("call `city`.`select_rez`();");
        void refresh()
        {
            dts = q.selectAny("call `city`.`select_list_sc_mainlistr`();");
            dataGridView1.DataSource = dts;
        }

        void refresh(int codSc0)
        {
            dts = q.selectAny(string.Concat("call `city`.`select_list_sc_mainlistrwc`(", codSc0, ");"));
            dataGridView1.DataSource = dts;
        }
        void refresh(string strRLike)
        {
            dts = q.selectAny(string.Concat("call `city`.`select_list_sc_mainlistrw`( '", strRLike, "');"));
            dataGridView1.DataSource = dts;
        }
        private void cellclick_edit()
        {
            int xx = dataGridView1.SelectedCells[0].ColumnIndex;
            object y = dataGridView1.SelectedCells[0].Value;
            int yy = dataGridView1.SelectedCells[0].RowIndex;
            
            object ov = "";
            string codSc = dataGridView1.Rows[yy].Cells[2].Value.ToString();
            string codrz = dataGridView1.Rows[yy].Cells[3].Value.ToString();

            string sql = "";

            if (xx == 0) //наименование продукции sc
            {
               
            }
            else if (xx == 1)  //наименование продукции rz
            {
                DataTable dt = q.selectAny("call `city`.`select_rz`();");
                ETALON.listAny f = new ETALON.listAny(dt); f.ShowDialog();

                if (f.IsOk)
                {
                    //`rz_update_list_sc_mainlistr`(codrz0 int, codsc0 int)
                    string s1 = string.Concat(
                        "call `city`.`rz_update_list_sc_mainlistr` (",
                        f.sCod , " , ",
                        codSc , ");");
                    q.UpdateData(s1);
                    refresh(xx,yy);
                }
            }
            else if (xx == 2) 
            {
               
            }
            else if (xx == 3)  
            {
                
            }
            
        }

        private void editValue()
        {
        }

        private void cellclick_del()
        {
            int xx = dataGridView1.SelectedCells[0].ColumnIndex;
            int yy = dataGridView1.SelectedCells[0].RowIndex;
            vv.rz.currentCod123 = 0;
            vv.rz.currentNameCodSc = dataGridView1.SelectedRows[0].Cells[2].Value; //h.m(o123);

            q.UpdateData(rz.sql.delete_list_sc_mainlistr(vv.rz.currentNameCodSc)); 
            refresh(xx,yy);
  
        }
        private void cellclick_work()
        {

        }
        private void cellclick_non()
        {

        }

        private void setCurrent()
        {
            vv.rz.currentColumn = dataGridView1.SelectedColumns[0].Index;
            vv.rz.currentRow = dataGridView1.SelectedRows[0].Index;
        }
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            setMode(city7.rzpt.modeWAED.add);
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            setMode(city7.rzpt.modeWAED.delete);
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            setMode(city7.rzpt.modeWAED.edit);
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            cellclick();
        }

        private void toolStripDropDownButton3_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "- (888)";
            vv.rz.add_prod_default = "- (888)";

            setMode(city7.rzpt.modeWAED.work);
        }



        private void toolStripTextBox1_KeyUp(object sender, KeyEventArgs e)
        {
            refreshIf();
        }

        void refreshIf()
        {
            if (toolStripTextBox1.Text.Length > 0)
            { refresh(toolStripTextBox1.Text); }

        }



        private void toolStripStatusLabel1_MouseDown(object sender, MouseEventArgs e)
        {
            toolStripStatusLabel1.DisplayStyle = ToolStripItemDisplayStyle.Text;
        }

        private void toolStripStatusLabel1_MouseUp(object sender, MouseEventArgs e)
        {
            toolStripStatusLabel1.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
            toolStripStatusLabel1.Text = "- (888)"; vv.rz.add_prod_default = "- (888)";
        }

        private void FormRzpt_FormClosed(object sender, FormClosedEventArgs e)
        {
            q.con.cc();
        }

        private void toolStripDropDownButton1_Click(object sender, EventArgs e)
        {
        }
        private int cf(int nc, int w)
        {
            return nc * w;
        }
        private void RZPT_print(System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics; string oo = ""; string om = "";

            currentPage++;
            //$$$ Настройка страницы            
            e.PageSettings.Margins.Top = 20; e.PageSettings.Margins.Left = 20; e.PageSettings.Margins.Right = 20; e.PageSettings.Margins.Bottom = 50;

            int xr = 40, yr = 15, x = 20, y = 25 + yr;

            #region  Rectangle and Width and Heght and fornt
            Rectangle r1, r2, r3, r4, r5;
            Rectangle rg;
            Rectangle rs;
            Rectangle rHeadline, rPageNumber;
            int wg = 330, ww = 30;
            int w1 = 30, w2 = 0, w3 = 0, w4 = 250, w5 = 50;
            int h = 15, hh = 5, f = 8, ff = 10;
            int hg = 20;
            #endregion

            #region other declaration
            int ic = dts.Rows.Count;
            string n0 = "", n5 = "", n10 = "", n15 = "";
            colorr c0 = colorr.white, c5 = colorr.white, c10 = colorr.white, c15 = colorr.white;
            string sz = string.Concat("Рецептуры цеха для кафэ СИТИ ");
            #endregion

            #region Aligment
            System.Drawing.StringFormat sfc = new StringFormat(); sfc.Alignment = StringAlignment.Center;
            System.Drawing.StringFormat sfo = new StringFormat(); sfo.Alignment = StringAlignment.Far;
            System.Drawing.StringFormat sfg = new StringFormat(); sfg.LineAlignment = StringAlignment.Far;
            #endregion

            rHeadline = new Rectangle(xr, yr, 500, h + 5);
            rPageNumber = new Rectangle(xr + 650, yr, 70, h + 5);

            if (currentPage == 1) g.DrawString(sz, new Font("Arial", 12), Brushes.Black, rHeadline);

            g.DrawString(string.Concat("Стр.", currentPage), new Font("Arial", 12), Brushes.Black, rPageNumber, sfo);
            object okosh = 0, okol = 0;
            //okosh = dts.Compute("SUM(kolv)", "kolv>=0");
            //okol = dts.Compute("SUM(kol)", "kol>=0");
            //---------------------- Итоги
            #region r1---r21

            r1 = new Rectangle(x + vv.RPT.col * 330, y, w1, h);
            //r2 = new Rectangle(x + w1, y, w2, h);
            //r3 = new Rectangle(x + w1 + w2, y, w3, h);
            r4 = new Rectangle(x + vv.RPT.col * (wg + ww) + w1 + w2 + w3, y, w4, h);
            r5 = new Rectangle(x + vv.RPT.col * (wg + ww) + w1 + w2 + w3 + w4, y, w5, h);

            #endregion

            #region drawStr
            //g.DrawString("Итого : ", new Font("Arial", f), Brushes.Black, r2);
            //g.DrawString(okosh.ToString(), new Font("Arial", f), Brushes.Black, r3, sfc);
            //g.DrawString(okol.ToString(), new Font("Arial", f), Brushes.Black, r4, sfc);
            #endregion
            //----------------------

            y = y + h;
            //---------------------- Caption
            #region r1---r21

            r1 = new Rectangle(x + vv.RPT.col * (wg + ww), y, w1, h);
            //r2 = new Rectangle(x + w1, y, w2, h);
            //r3 = new Rectangle(x + w1 + w2, y, w3, h);
            r4 = new Rectangle(x + vv.RPT.col * (wg + ww) + w1 + w2 + w3, y, w4, h);
            r5 = new Rectangle(x + vv.RPT.col * (wg + ww) + w1 + w2 + w3 + w4, y, w5, h);

            g.DrawRectangle(Pens.LightSteelBlue, r1);
            //g.DrawRectangle(Pens.LightSteelBlue, r2);
            //g.DrawRectangle(Pens.LightSteelBlue, r3);
            g.DrawRectangle(Pens.LightSteelBlue, r4);
            g.DrawRectangle(Pens.LightSteelBlue, r5);


            #endregion

            #region drawStr
            g.DrawString("№пп", new Font("Arial", f), Brushes.Black, r1, sfc);
            g.DrawString("Наименование сырья", new Font("Arial", f), Brushes.Black, r4, sfc);
            g.DrawString("кол", new Font("Arial", f), Brushes.Black, r5, sfc);
            #endregion
            //----------------------

            y = y + h; vv.RPT.yb = y;
            while (linesPrint < ic)
            {

                if (vv.RPT.lp == 0)
                {
                    rg = new Rectangle(x + vv.RPT.col * (wg + ww), y, wg, hg);
                    vv.RPT.stringControlGroup = n(dts.Rows[linesPrint][0]).ToString();
                    g.DrawString(vv.RPT.stringControlGroup, new Font("Arial", f), Brushes.Black, rg);
                    y = y + h; vv.RPT.lp++;
                }
                else
                {
                    if (vv.RPT.stringControlGroup == n(dts.Rows[linesPrint][0]).ToString())
                    {
                        #region r1---r21

                        r1 = new Rectangle(x + vv.RPT.col * (wg + ww), y, w1, h);
                        r4 = new Rectangle(x + vv.RPT.col * (wg + ww) + w1 + w2 + w3, y, w4, h);
                        r5 = new Rectangle(x + vv.RPT.col * (wg + ww) + w1 + w2 + w3 + w4, y, w5, h);

                        g.DrawRectangle(Pens.LightSteelBlue, r1);
                        g.DrawRectangle(Pens.LightSteelBlue, r4);
                        g.DrawRectangle(Pens.LightSteelBlue, r5);

                        #endregion

                        #region drawStr
                        g.DrawString(n(linesPrint + 1), new Font("Arial", f), Brushes.Black, r1);
                        g.DrawString(n(dts.Rows[linesPrint][2]), new Font("Arial", f), Brushes.Black, r4);
                        g.DrawString(n(dts.Rows[linesPrint][3]), new Font("Arial", f), Brushes.Black, r5);
                        #endregion

                        y += h; linesPrint++; vv.RPT.lp++;
                        if ((y >= e.PageBounds.Height - 50) && vv.RPT.col > 0)
                        { e.HasMorePages = true; vv.RPT.col = 0; return; }
                        else if (y >= e.PageBounds.Height - 50)
                        { y = vv.RPT.yb; vv.RPT.col++; }
                    }
                    else
                    {

                        rg = new Rectangle(x + vv.RPT.col * (wg + ww), y, wg, hg);
                        vv.RPT.stringControlGroup = n(dts.Rows[linesPrint][0]).ToString();
                        g.DrawString(vv.RPT.stringControlGroup, new Font("Arial", f), Brushes.Black, rg);
                        y = y + h; vv.RPT.lp++;
                        if (y >= e.PageBounds.Height - 50 && vv.RPT.col > 0)
                        { e.HasMorePages = true; vv.RPT.col = 0; return; }
                        else if (y >= e.PageBounds.Height - 50)
                        { y = vv.RPT.yb; vv.RPT.col++; }
                    }
                }
            }
            linesPrint = 0; vv.RPT.col = 0; e.HasMorePages = false;
        }

        private void RZPT_reestr_print(System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics; string oo = ""; string om = "";

            currentPage++;
            //$$$ Настройка страницы            
            e.PageSettings.Margins.Top = 20; e.PageSettings.Margins.Left = 20; e.PageSettings.Margins.Right = 20; e.PageSettings.Margins.Bottom = 50;

            int xr = 40, yr = 15, x = 20, y = 25 + yr;

            #region  Rectangle and Width and Heght and fornt
            Rectangle r1, r2;
            Rectangle rg;
            Rectangle rs;
            Rectangle rHeadline, rPageNumber;
            int wg = 330, ww = 30;
            int w1 = 30, w2 = 300;
            int h = 15, hh = 5, f = 8, ff = 10;
            int hg = 20;
            #endregion

            #region other declaration
            int ic = dts.Rows.Count;
            string n0 = "", n5 = "", n10 = "", n15 = "";
            colorr c0 = colorr.white, c5 = colorr.white, c10 = colorr.white, c15 = colorr.white;
            string sz = string.Concat("Реестр продукции с рецептурами по кафэ СИТИ ");
            #endregion

            #region Aligment
            System.Drawing.StringFormat sfc = new StringFormat(); sfc.Alignment = StringAlignment.Center;
            System.Drawing.StringFormat sfo = new StringFormat(); sfo.Alignment = StringAlignment.Far;
            System.Drawing.StringFormat sfg = new StringFormat(); sfg.LineAlignment = StringAlignment.Far;
            #endregion

            rHeadline = new Rectangle(xr, yr, 500, h + 5);
            rPageNumber = new Rectangle(xr + 650, yr, 70, h + 5);

            if (currentPage == 1) g.DrawString(sz, new Font("Arial", 12), Brushes.Black, rHeadline);

            g.DrawString(string.Concat("Стр.", currentPage), new Font("Arial", 12), Brushes.Black, rPageNumber, sfo);
            object okosh = 0, okol = 0;
            //okosh = dts.Compute("SUM(kolv)", "kolv>=0");
            //okol = dts.Compute("SUM(kol)", "kol>=0");
            //---------------------- Итоги
            #region r1---r21

            r1 = new Rectangle(x + vv.RPT.col * 330, y, w1, h);
            r2 = new Rectangle(x + w1, y, w2, h);

            #endregion

            #region drawStr
            //g.DrawString("Итого : ", new Font("Arial", f), Brushes.Black, r2);
            //g.DrawString(okosh.ToString(), new Font("Arial", f), Brushes.Black, r3, sfc);
            //g.DrawString(okol.ToString(), new Font("Arial", f), Brushes.Black, r4, sfc);
            #endregion
            //----------------------

            y = y + h;
            //---------------------- Caption
            #region r1---r21

            r1 = new Rectangle(x + vv.RPT.col * (wg + ww), y, w1, h);
            r2 = new Rectangle(x + w1, y, w2, h);

            g.DrawRectangle(Pens.LightSteelBlue, r1);
            g.DrawRectangle(Pens.LightSteelBlue, r2);


            #endregion

            #region drawStr
            g.DrawString("№пп", new Font("Arial", f), Brushes.Black, r1, sfc);
            g.DrawString("Наименование ", new Font("Arial", f), Brushes.Black, r2, sfc);
            #endregion
            //----------------------

            y = y + h; vv.RPT.yb = y;
            while (linesPrint < ic)
            {

                #region r1---r21

                r1 = new Rectangle(x + vv.RPT.col * (wg + ww), y, w1, h);
                r2 = new Rectangle(x + vv.RPT.col * (wg + ww) + w1, y, w2, h);

                g.DrawRectangle(Pens.LightSteelBlue, r1);
                g.DrawRectangle(Pens.LightSteelBlue, r2);


                #endregion

                #region drawStr
                g.DrawString(n(linesPrint + 1), new Font("Arial", f), Brushes.Black, r1);
                g.DrawString(n(dts.Rows[linesPrint][0]), new Font("Arial", f), Brushes.Black, r2);
                #endregion

                y += h; linesPrint++; vv.RPT.lp++;
                if ((y >= e.PageBounds.Height - 50) && vv.RPT.col > 0)
                { e.HasMorePages = true; vv.RPT.col = 0; return; }
                else if (y >= e.PageBounds.Height - 50)
                { y = vv.RPT.yb; vv.RPT.col++; }


            }
            linesPrint = 0; vv.RPT.col = 0; e.HasMorePages = false;
        }
        private void RZPT_print0(System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics; string oo = ""; string om = "";

            currentPage++;
            //$$$ Настройка страницы            
            e.PageSettings.Margins.Top = 20; e.PageSettings.Margins.Left = 20; e.PageSettings.Margins.Right = 20; e.PageSettings.Margins.Bottom = 50;

            int xr = 40, yr = 15, x = 20, y = 25 + yr;

            #region  Rectangle and Width and Heght and fornt
            Rectangle r1, r2, r3, r4, r5;

            Rectangle rs;
            Rectangle rHeadline, rPageNumber;
            int w1 = 30, w2 = 300, w3 = 40, w4 = 300, w5 = 50;
            int h = 15, hh = 30, f = 8, ff = 10;
            #endregion

            #region other declaration
            int ic = dts.Rows.Count;
            string n0 = "", n5 = "", n10 = "", n15 = "";
            colorr c0 = colorr.white, c5 = colorr.white, c10 = colorr.white, c15 = colorr.white;
            string sz = string.Concat("Рецептуры цеха для кафэ СИТИ ");
            #endregion

            #region Aligment
            System.Drawing.StringFormat sfc = new StringFormat(); sfc.Alignment = StringAlignment.Center;
            System.Drawing.StringFormat sfo = new StringFormat(); sfo.Alignment = StringAlignment.Far;
            System.Drawing.StringFormat sfg = new StringFormat(); sfg.LineAlignment = StringAlignment.Far;
            #endregion

            rHeadline = new Rectangle(xr, yr, 500, h + 5);
            rPageNumber = new Rectangle(xr + 650, yr, 70, h + 5);

            if (currentPage == 1) g.DrawString(sz, new Font("Arial", 12), Brushes.Black, rHeadline);

            g.DrawString(string.Concat("Стр.", currentPage), new Font("Arial", 12), Brushes.Black, rPageNumber, sfo);
            object okosh = 0, okol = 0; okosh = dts.Compute("SUM(kolv)", "kolv>=0"); okol = dts.Compute("SUM(kol)", "kol>=0");
            //---------------------- Итоги
            #region r1---r21

            r1 = new Rectangle(x, y, w1, h);
            r2 = new Rectangle(x + w1, y, w2, h);
            r3 = new Rectangle(x + w1 + w2, y, w3, h);
            r4 = new Rectangle(x + w1 + w2 + w3, y, w4, h);
            r5 = new Rectangle(x + w1 + w2 + w3 + w4, y, w5, h);

            #endregion

            #region drawStr
            g.DrawString("Итого : ", new Font("Arial", f), Brushes.Black, r2);
            g.DrawString(okosh.ToString(), new Font("Arial", f), Brushes.Black, r3, sfc);
            g.DrawString(okol.ToString(), new Font("Arial", f), Brushes.Black, r4, sfc);
            #endregion
            //----------------------

            y = y + h;
            //---------------------- Caption
            #region r1---r21

            r1 = new Rectangle(x, y, w1, h);
            r2 = new Rectangle(x + w1, y, w2, h);
            r3 = new Rectangle(x + w1 + w2, y, w3, h);
            r4 = new Rectangle(x + w1 + w2 + w3, y, w4, h);
            r5 = new Rectangle(x + w1 + w2 + w3 + w4, y, w5, h);

            g.DrawRectangle(Pens.LightSteelBlue, r1);
            g.DrawRectangle(Pens.LightSteelBlue, r2);
            g.DrawRectangle(Pens.LightSteelBlue, r3);
            g.DrawRectangle(Pens.LightSteelBlue, r4);
            g.DrawRectangle(Pens.LightSteelBlue, r5);


            #endregion

            #region drawStr
            g.DrawString("№пп", new Font("Arial", f), Brushes.Black, r1, sfc);
            g.DrawString("Наименование продукции", new Font("Arial", f), Brushes.Black, r2, sfc);
            g.DrawString("кол вых", new Font("Arial", f), Brushes.Black, r3, sfc);
            g.DrawString("Наименование сырья", new Font("Arial", f), Brushes.Black, r4, sfc);
            g.DrawString("кол", new Font("Arial", f), Brushes.Black, r5, sfc);
            #endregion
            //----------------------

            y = y + h;
            while (linesPrint < ic)
            {

                #region r1---r21

                r1 = new Rectangle(x, y, w1, h);
                r2 = new Rectangle(x + w1, y, w2, h);
                r3 = new Rectangle(x + w1 + w2, y, w3, h);
                r4 = new Rectangle(x + w1 + w2 + w3, y, w4, h);
                r5 = new Rectangle(x + w1 + w2 + w3 + w4, y, w5, h);

                g.DrawRectangle(Pens.LightSteelBlue, r1);
                g.DrawRectangle(Pens.LightSteelBlue, r2);
                g.DrawRectangle(Pens.LightSteelBlue, r3);
                g.DrawRectangle(Pens.LightSteelBlue, r4);
                g.DrawRectangle(Pens.LightSteelBlue, r5);

                #endregion

                #region drawStr
                g.DrawString(n(linesPrint + 1), new Font("Arial", f), Brushes.Black, r1);
                g.DrawString(n(dts.Rows[linesPrint][0]), new Font("Arial", f), Brushes.Black, r2);
                g.DrawString(n(dts.Rows[linesPrint][1]), new Font("Arial", f), Brushes.Black, r3);
                g.DrawString(n(dts.Rows[linesPrint][2]), new Font("Arial", f), Brushes.Black, r4);
                g.DrawString(n(dts.Rows[linesPrint][3]), new Font("Arial", f), Brushes.Black, r5);
                #endregion

                y += h; linesPrint++;
                if (y >= e.PageBounds.Height - 50) { e.HasMorePages = true; return; }

            }
            linesPrint = 0; e.HasMorePages = false;
        }
        private string nn(object o)
        {
            string s = "0";
            if (Convert.ToInt32(o) < 10) { s = string.Concat("0", o); } else { s = o.ToString(); }
            return s;
        }
        private string n(object o)
        {
            string s = "";
            if (o.ToString() != "0" && o.ToString() != "-") { s = o.ToString(); }
            return s;
        }
        

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
           
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
           
        }

        private void toolStripMenuItem2_Click_1(object sender, EventArgs e)
        {

        }

        private void toolStripButton3_Click_1(object sender, EventArgs e)
        {
            setMode(city7.rzpt.modeWAED.add);
        }

      




        

       
    }
}
